package BookCreated;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Loginout.UserBean;

@WebServlet("/DeleteCalnums")
public class DeleteCalnums extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		UserBean UB = (UserBean) session.getAttribute("ub");
		if (UB == null) {
			response.sendRedirect("error.html");
		} else {

			response.setContentType("text/html;charset=UTF-8");
			request.setCharacterEncoding("UTF-8");

			PrintWriter w = response.getWriter();
			String calid = request.getParameter("calid");	
			BookCalnums calnum = new BookCalnums();
			if (!calid.isEmpty()){
				try {
					calnum = BooksCalnumsDAO.getBookCalnums(calid);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				request.setAttribute("bookcal", calnum);
				request.getRequestDispatcher("DeleteCalnumsPage.jsp").forward(request,
						response);

			}
			
		}
	}

}
